<template>
  <div class="TPagination text-right">
    <el-pagination
      :current-page="pagination.page"
      :total="pagination.total"
      :page-size="pagination.size"
      :page-sizes="sizes"
      :layout="layout"
      :hide-on-single-page="hideOnsinglePage"
      class="px-0 pb-0 pt-[16px]"
      background
      @size-change="onSizeChange"
      @current-change="onCurrentChange"
    />
  </div>
</template>

<script>
export default {
  name: "TPagination",
  props: {
    pagination: {
      page: {
        type: Number,
        required: true,
        default: 1,
      },
      size: {
        type: Number,
        required: true,
        default: 10,
      },
      total: {
        type: Number,
        required: true,
        default: 10,
      },
    },
    hideOnsinglePage: {
      type: Boolean,
      required: false,
      default: false,
    },
    sizes: {
      type: Array,
      required: false,
      default: () => [10, 20, 50, 100],
    },
    layout: {
      type: String,
      required: false,
      default: "->, total, sizes, prev, pager, next, jumper",
    },
  },
  methods: {
    onSizeChange(size) {
      this.$emit("pageChange", {
        page: 1,
        size,
      });
    },
    onCurrentChange(page) {
      this.$emit("pageChange", {
        page,
        size: this.pagination.size,
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
